package com.example.takephoto

import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

class MainActivity4 : AppCompatActivity() {
    private lateinit var tvCount: TextView
    var count = 0
        set(value) {
            field = value
            tvCount.text = getString(R.string.sheep_count, value)
        }
    val MainTag = "MainActivity4"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main4)
        val btnBack =findViewById<Button>(R.id.btnBack)
        btnBack.setOnClickListener {
            finish()
        }
        tvCount = findViewById(R.id.tvCount)
        val btnReset = findViewById<Button>(R.id.btnReset)

        btnReset.setOnClickListener {
            count++
        }

        Log.d(MainTag, "onCreate")
    }

    override fun onStart() {
        super.onStart()
        Log.d(MainTag, "onStart")
    }

    override fun onResume() {
        super.onResume()
        Log.d(MainTag, "onResume")
    }

    override fun onPause() {
        super.onPause()
        Log.d(MainTag, "onPause")
    }

    override fun onStop() {
        super.onStop()
        Log.d(MainTag, "onStop")
    }

    override fun onRestart() {
        super.onRestart()
        Log.d(MainTag, "onRestart")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(MainTag, "onDestroy")
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        Log.d(MainTag, "onSaveInstanceState")
        outState.putInt("count", count)
    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)
        Log.d(MainTag, "onRestoreInstanceState")
        count = savedInstanceState.getInt("count")
    }
}